package com.yidu.hbatsams.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsams.dao.AtsEmpLeaderMapper;
import com.yidu.hbatsams.domain.AtsEmpLeader;
import com.yidu.hbatsams.service.emp.AtsEmpLeaderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.List;

/**
 * 中心领导管理的实现类
 */
@Service
public class AtsEmpLeaderServiceImpl implements AtsEmpLeaderService {

    @Resource
    AtsEmpLeaderMapper atsEmpLeaderMapper;//每个方法都需要使用，设为成员变量

    /**
     * 分页查询+模糊查询
     * @param pageNum
     * @param pageSize
     * @param leaderName
     * @return
     */
    @Override
    public List<AtsEmpLeader> selectAll(Integer pageNum, Integer pageSize, String leaderName,String startTime,String endTime) {
        PageHelper.startPage(pageNum, pageSize);
        //System.out.println(leaderName);
        List<AtsEmpLeader> ats = atsEmpLeaderMapper.selectAll(leaderName,startTime,endTime);
        return ats;
    }


    /**
     * 查询行数
     * @param
     * @return
     */
    @Override
    public Long count() {
        return atsEmpLeaderMapper.count();
    }
    /**
     * 逻辑删除
     * @param leaderId
     */
    @Override
    public int deleteByPrimaryKey(Integer leaderId) {
       int ats = atsEmpLeaderMapper.deleteByPrimaryKey(leaderId);
        return ats;
    }

    /**
     * 新增
     * @param record
     * @return
     */
    @Override
    public int insert(AtsEmpLeader record) {

        record.setIsva(1);
        record.setCreatTime(new Date(System.currentTimeMillis()));
        int ats = atsEmpLeaderMapper.insert(record);
        return ats;
    }

    /**
     * 根据ID进行查询 用于修改显示
     * @param leaderId
     * @return
     */
    @Override
    public AtsEmpLeader selectByPrimaryKey(Integer leaderId) {
       AtsEmpLeader ats = atsEmpLeaderMapper.selectByPrimaryKey(leaderId);

        return ats;
    }



    /**
     * 修改
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKey(AtsEmpLeader record) {
        record.setIsva(1);
        AtsEmpLeader ats = atsEmpLeaderMapper.selectByPrimaryKey(record.getLeaderId());
        record.setCreatTime(ats.getCreatTime());
        return atsEmpLeaderMapper.updateByPrimaryKey(record);
    }


}
